<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Comet echo RPC</title>

    <script type="text/javascript" src="${pageContext.request.contextPath}/js/dojo/dojo.js.uncompressed.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/dojox/cometd.js.uncompressed.js"></script>
    
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/behaviour.js"></script>

    <script language="JavaScript" type="text/javascript">

        dojo.require("dojox.cometd");

        $ = dojo.byId;
        
        var EvUtil = {
            getKeyCode : function(ev) {
                var keyc;
                if (window.event) {
                    return window.event.keyCode;
                } else {
                    return ev.keyCode;
                }
            }
        };

        var echoBehaviours = {
            '#phrase' : function(element) {
                element.setAttribute("autocomplete", "OFF");
                element.onkeyup = function(ev) {
                    var keyc = EvUtil.getKeyCode(ev);
                    if (keyc == 13 || keyc == 10) {
                        echoRpc($('phrase').value);
                        $('phrase').value = '';
                        return false;
                    }
                    return true;
                }
            },

            '#sendB' : function(element) {
                element.onclick = function(event) {
                    echoRpc($('phrase').value);
                    $('phrase').value = '';
                    return false;
                }
            }
        };

        function echoRpc(msg) {
            dojox.cometd.publish("/service/echo", msg);
        }

        Behaviour.register(echoBehaviours);
        
        function echoRpcReturn(msg) {
            $("responses").innerHTML += msg.timestamp + " " + msg.channel + ": " + msg.data + "<br/>";
        }

        function setup() {
            dojox.cometd.init("${pageContext.request.contextPath}/cometd");
            dojox.cometd.subscribe("/service/echo", "echoRpcReturn");
        }        

        dojo.addOnLoad(setup);
    </script>
</head>
<body>

<h1>Echo Test (Spring Enabled)</h1>

<div>Echo:&nbsp;<input id="phrase" type="text"></input> <input id="sendB" class="button" type="submit" name="join"
                                                               value="Send"/>
</div>
<pre id="responses"></pre>

<h3>Java Code</h3>

    <pre>
        ...
    </pre>

<h3>Spring Configuration</h3>

    <pre>
        ...
    </pre>

</body>
</html>
